package com.example.lottery.dao.mapper;


import com.example.lottery.dao.dataobject.Encrypt;
import com.example.lottery.dao.dataobject.UserDO;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface UserMapper {

    @Select("select count(*) from user where email = #{email}")
    int countByMail(@Param("email") String email);

    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    int countByPhoneNumber(@Param("phoneNumber") Encrypt phoneNumber);

    @Insert("insert into user (user_name,email,phone_number,password,identity) values " +
            " (#{userName},#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")//设置主键给id
    void insert(UserDO userDo);

    @Select("select * from user where email = #{email}")
    UserDO selectByMail(String loginName);

    @Select("<script> select  * from user <if test=\"identity!=null\"> where identity = #{identity} </if> order by id desc </script>")
    List<UserDO> selectUserListByIdentity(String identityString);

    @Select("<script> select id from user where id in <foreach item='item' collection='items' open='(' separator=',' close=')'> #{item} </foreach> </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> id);

    @Select("<script> select * from user where id in <foreach item='item' collection='items' open='(' separator=',' close=')'> #{item} </foreach> </script>")
    List<UserDO> batchSelectByIds(@Param("items") List<Long> id);
}
